package chances.webui.taglibs;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.jsp.JspException;

import chances.webui.model.Timeline;
import chances.webui.model.TimelineNode;

@SuppressWarnings("serial")
public class TimelineTag extends WebUITag {

	private Timeline timeLine;
	
	private String dataUrl;
	private String datas;
	private Integer size;
	private boolean auto = false;
	
	private String title;
	private String operator;
	private String messageFormat;
	private String time;
	private String clickcondition;
	private String onclick;
	private String clicktip;

	@Override
	protected void initContext(Map<String, Object> context) {
		context.put("lookups",this.getJson(timeLine.getLookups()));
		context.put("contextPath",pageContext.getServletContext().getContextPath());
		WebPageContext.getWebPageContext(pageContext).addComponent(timeLine);
	}
	
	public void addLookup(String name, Object lookup) {
		this.getLookups().put(name, lookup);
	}
	
	@Override
	protected void reset() {
		this.timeLine = new Timeline();
		super.reset();
	}
	@Override
	public int doEndTag() throws JspException {
		if (getMessageFormat() == null && this.bodyContent != null) {
			setMessageFormat(this.getBodyContent().getString());
		}
		return super.doEndTag();
	}

	public Map<String, Object> getLookups() {
		return timeLine.getLookups();
	}

	public void setLookups(Map<String, Object> lookups) {
		timeLine.setLookups(lookups);
	}

	public void addTimelineNode(TimelineNode timelineNode) {
		timeLine.addTimelineNode(timelineNode);
	}

	public void setTimelineNodes(List<TimelineNode> timelineNodes) {
		timeLine.setTimelineNodes(timelineNodes);
	}

	public Set<Entry<String, String>> getLookupNames() {
		return timeLine.getLookupNames();
	}

	public List<TimelineNode> getTimelineNodes() {
		return timeLine.getTimelineNodes();
	}

	public Timeline getTimeLine() {
		return timeLine;
	}

	public void setTimeLine(Timeline timeLine) {
		this.timeLine = timeLine;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getMessageFormat() {
		return messageFormat;
	}

	public void setMessageFormat(String messageFormat) {
		this.messageFormat = messageFormat;
	}

	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	public String getClicktip() {
		return clicktip;
	}

	public void setClicktip(String clicktip) {
		this.clicktip = clicktip;
	}

	public String getDataUrl() {
		return dataUrl;
	}

	public void setDataUrl(String dataUrl) {
		this.dataUrl = dataUrl;
	}

	public String getClickcondition() {
		return clickcondition;
	}

	public void setClickcondition(String clickcondition) {
		this.clickcondition = clickcondition;
	}
	
	public String getDatas() {
		return datas;
	}

	public void setDatas(String datas) {
		this.datas = datas;
	}

	public Integer getSize() {
		return size;
	}

	public void setSize(Integer size) {
		this.size = size;
	}

	public boolean isAuto() {
		return auto;
	}

	public void setAuto(boolean auto) {
		this.auto = auto;
	}
}
